﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using HelloWorld;

class main
{
    private static string from = @"C:\";
    private static string dest = @"C:\";
    


    static void Main(string[] args)
    {
        string s = "345678fghjvbnm";
        Console.WriteLine(s[0..^4]);

        string path = @"D:\听歌\7-玄觞\玄觞 - 吹灭小山河（翻自 司南）.mp3";
        string parentName = new DirectoryInfo(path).Parent.FullName;
        Console.WriteLine(parentName);
        string dirName = new DirectoryInfo(path).Name;
        Console.WriteLine(dirName);
        Console.WriteLine(parentName + Path.DirectorySeparatorChar + dirName);
 //       Directory.Move(path, parentName + Path.PathSeparator + dirName);


    }


    private static void GetList(string path, List<string> list)
    {
        // 添加列表
        if (        // 驱动器不判断
                                                    // 对于文件夹，要求存在且非隐藏
            (Directory.Exists(path) && !((new DirectoryInfo(path).Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)))
        {
            string[] dirs = Directory.GetFileSystemEntries(path);
            if (dirs == null || dirs.Length == 0)
            {
                Directory.Delete(path);
            }
            foreach (string s in dirs)
            {
                GetList(s, list);
            }
        }   // 对于文件，要求存在且非隐藏
        else if (File.Exists(path) && !((new FileInfo(path).Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
        {
            list.Add(path);
            Console.WriteLine(path);
        }
        else
        {
            Console.WriteLine(path + " 是隐藏文件");
        }
    }

    private static string GetSHA256(string path)
    {
        SHA256 mySHA256 = SHA256.Create();
        FileStream fileStream = new FileInfo(path).Open(FileMode.Open);
        fileStream.Position = 0;
        byte[] hashValue = mySHA256.ComputeHash(fileStream);
        fileStream.Close();
        return PrintByteArray(hashValue);
    }

    public static string PrintByteArray(byte[] array)
    {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < array.Length; i++)
        {
            result.Append($"{array[i]:X2}");
            if ((i % 4) == 3) result.Append(" ");
        }
        return result.ToString();
    }
    public void produceData()
    {
        Random rd = new Random();
        string file = "D:\\随机文件" + (long)((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds) + ".zip";
        StreamWriter sw = new StreamWriter(file, true, Encoding.UTF8);
        string rdString = "";
        for (int i = 0; i < 10; i++)
        {
            rdString += rd.Next();
        }
        using (sw)
        {
            for (int i = 0; i < 50000000; i++)
            {
                sw.Write(rdString);
            }
        }
        sw.Close();
    }


}
